<template>
	<view class="repair-content">
		<view class="padding-lr">
			<formItem :label="item.label" v-for="(item,index) in list" :isSlot="item.isSlot" :slotName="item.slotName"
				:key="index" :titleType="item.titleType" :rightIcon="item.rightIcon" :disabled="item.disabled"
				v-model="form[item.model]" @rightClick="event(item,index)">
				<!-- 送修人 -->
				<template #repairMan>
					<view class="rightContent">
						<u-input v-model="form['repairMan']" :disabled="!isChange" type="text" :border="false" :clearable="false" input-align="right" />
					</view>
				</template>
				<!-- 车牌号 -->
				<template #carLicense>
					<view class="rightContent">
						<u-input v-model="form['carLicense']" :disabled="!isChange" type="text" :border="false" :clearable="false" input-align="right" @blur="inputBlur('carLicense',form['carLicense'])"/>
					</view>
				</template>
				<!-- 联系电话 -->
				<template #repairTel>
					<view class="phoneColor">
						<!-- <u-icon name="phone" color="#4f75be" size="36"></u-icon> -->
						<u-input v-model="form['repairTel']" :disabled="!isChange" type="text" :border="false" :clearable="false" input-align="right"/>
					</view>
				</template>
				<!-- 行驶里程 -->
				<template #mileage>
					<view class="rightContent">
						<u-input v-model="mileage" type="text" disabled :border="false" :clearable="false" input-align="right" placeholder="暂无数据"/>
					</view>
				</template>
				<!-- 服务顾问 -->
				<template #saName>
					<view class="rightContent">
						<u-input v-model="form['saName']" type="text" :disabled="!isChange" :border="false" :clearable="false" input-align="right"/>
					</view>
				</template>
				<!-- 预约单 -->
				<template #reserveOrderCode>
					<view class="rightContent" @click="rightSelected('reserveOrderCode')">
						{{$utils.eliminate(form.reserveOrderCode)}}
						<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
					</view>
				</template>
				<!-- 服务活动 -->
				<template #serviceActivities>
					<view class="rightContent" @click="rightSelected('serviceActivities')">
						{{$utils.eliminate(form.serviceActivities)}}
						<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
					</view>
				</template>
				<!-- 套餐精品 -->
				<template #packageBoutique>
					<view class="rightContent" @click="rightSelected('packageBoutique')">
						{{$utils.eliminate(form.packageBoutique)}}
						<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
					</view>
				</template>
				<!-- 保养项目 -->
				<template #maintenanceProgram>
					<view class="rightContent" @click="rightSelected('maintenanceProgram')">
						{{$utils.eliminate(form.maintenanceProgram)}}
						<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
					</view>
				</template>
				<!-- 客户描述 -->
				<template #csDesc>
					<view class="rightContent">
						<u-input v-model="form['csDesc']" :disabled="!isChange" type="text" :border="false" :clearable="false" input-align="right"/>
					</view>
				</template>
				<!-- 上次建议项目 -->
				<template #scRecommendItem>
					<view class="rightContent">
						<u-input v-model="scRecommendItem" type="text" disabled :border="false" :clearable="false" input-align="right" placeholder="暂无数据"/>
					</view>
				</template>
				<!-- 本次建议项目 -->
				<template #recommendItem>
					<view class="rightContent">
						<u-input v-model="form['recommendItem']" :disabled="!isChange" type="text" :border="false" :clearable="false" input-align="right"/>
					</view>
				</template>
				<!-- 取送车 -->
				<template #carDelivery>
					<view class="rightContent" @click="rightSelected('carDelivery')">
						{{$utils.eliminate(form.carDelivery)}}
						<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
					</view>
				</template>
				<!-- 拖车救援 -->
				<template #trailerRescue>
					<view class="rightContent" @click="rightSelected('trailerRescue')">
						{{$utils.eliminate(form.trailerRescue)}}
						<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
					</view>
				</template>
				<!-- 委外门店 -->
				<template #authorizedDlr>
					<view class="rightContent" @click="rightSelected('authorizedDlr')">
						{{$utils.eliminate(form.authorizedDlr)}}
						<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
					</view>
				</template>
			</formItem>
		</view>

		<!-- 维修项目 -->
		<view class="category">
			<category labelName="维修项目" rightName="费用合计" :editType="editType" openType="hours" :itemList="wisList"
				:labelList="shrinklist" deleteField="wiId" @openItem="openItem" @deleteItem="deleteItem" :totalMoney="form.wCoSts" 
				@changePartType="changePartType">
			</category>
		</view>
		<!-- 维修备件 -->
		<view class="category">
			<category ref="partNumRef" labelName="维修备件" rightName="工时费用合计" :editType="editType" openType="parts" :itemList="partsList"
				:labelList="sparelist" deleteField="partId" @openItem="openItem" @deleteItem="deleteItem" :totalMoney="form.pCoSts"
				@getPartsNum="partsNumIndex" @changePartType="changePartType">
			</category>
		</view>
		<!-- 其他费用 -->
		<view class="category">
			<category labelName="其他费用" rightName="费用合计" :editType="editType" openType="others" :itemList="othersList"
				:labelList="otherlist" deleteField="repairOtherId" @openItem="openItem" @deleteItem="deleteItem" :totalMoney="form.oCoSts" 
				@changePartType="changePartType">
			</category>
		</view>

		<parts ref="parts" @receiveItem="receiveParts" />
		<hours ref="hours" @receiveHours="receiveHours" />
		<others ref="others" @receiveOthers="receiveOthers" />
		

		<!-- 进厂时间/预计交车时间选择器 -->
		<u-picker mode="time" v-model="selectTime" @confirm="getDate" :params="dateformat"></u-picker>
		<!-- 选择器 -->
		<u-select v-model="showSelected" :list="rightList" height="400rpx" @confirm="confirmSelected">
		</u-select>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import formItem from '@/components/lt-formItem/index.vue';
	import category from './category.vue';
	import parts from '@/pages/common/parts.vue';
	import hours from '@/pages/common/workInghours.vue';
	import others from '@/pages/common/otherExpenses.vue';
	import { getActivitiesList, getSetMealList, getMaintenanceItem, findOutDlrList, lastTimeProposal, getCarInfoByVin, mileage, importWiSel, importPartSel, importOtherSel, repairTypeAndKind, carInforList} from '@/api/bookingManagement.js';

	export default {
		components: {
			formItem,
			category,
			parts,
			hours,
			others,
		},
		props: {
			list: {
				type: Array,
				default: []
			},
			form1: { // 维修工单查询的信息
				type: Object,
				default: {},
			},
			editType: {
				type: Boolean,
				default: true
			},
			isChange: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				rightList:[],//选择弹框数据
				carLicense:'',//车牌号
				scRecommendItem:'',//上次建议项目
				mileage:'',//行驶里程
				selectTime: false, //时间选择器
				distinguishTime: 0, //区分选中的哪个时间
				showSelected: false, //右边点击出现选择弹框
				rightItem: '', //选择器选中某项
				wisList: [], //维修项目
				partsList: [], //维修备件
				othersList: [], //其他费用
				form: {
					totalMoney:0,//合计总费用
					wisList:[],
					partsList:[],
					othersList:[]
				},
				dateformat: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					timestamp: true,
					second: true
				},
				//维修页面请求数据
				shrinklist: [{
						label: '工时',
						model: 'saleWiQty'
					}, {
						label: '费用',
						model: 'wiPrice'
					},
					{
						label: '维修类别',
						model: 'retRepairType'
					}, {
						label: '是否委外',
						model: 'isEntrust'
					}
				],
				sparelist: [{
					label: '数量',
					model: 'partQty',
					type: 'number'
				}, {
					label: '费用',
					model: 'partPrice'
				}, {
					label: '维修类别',
					model: 'retRepairType'
				}, {
					label: '是否委外',
					model: 'isEntrust'
				}],
				otherlist: [{
					label: '费用',
					model: 'otherPrice'
				}, {
					label: '维修类别',
					model: 'retRepairType'
				}
				],
			}
		},
		watch:{
			carLicense: {//车牌号
				handler(newVal){
					this.form.carLicense = this.newVal
				}
			},
			// 子页面数据
			form1: {
				handler(val){
					let arr= Object.keys(val)
					if(arr.length>0){
						this.form = val
						
						this.scRecommendItem = this.form.scRecommendItem//上次建议项目
						this.mileage = this.form.mileage
						
						this.wisList=this.form.listMapWi || this.form.wisList || []
						this.partsList=this.form.listMapPart || this.form.partsList || []
						this.othersList=this.form.listMapOther || this.form.othersList || []
					}
					console.log('form:',this.form)
					this.$forceUpdate()
				},
				deep:true
			},
			// partsList:{
			// 	handler(val){
			// 		this.$forceUpdate()
			// 	},
			// 	immediate:true
			// },
		},
		methods: {
			getForm(){
				return this.form
			},
			//点击文本框选择
			event(item, index) {
				this.distinguishTime = item.model === 'repairTime' ? 0 : 1
				if(!this.editType || !this.isChange) return
				if (item.model === 'repairTime' || item.model === 'preGetDate') {
					this.selectTime = true
				}
			},
			// 时间选择器返回值
			getDate(v) {
				if (!this.distinguishTime) { //进厂时间
					this.form.repairTime = v.year + '-' + v.month + '-' + v.day + ' ' + v.hour + ':' + v.minute + ':' + v.second
				} else { //预计交车时间
					this.form.preGetDate = v.year + '-' + v.month + '-' + v.day + ' ' + v.hour + ':' + v.minute + ':' + v.second
				}
				this.$emit('formEcho',this.form)
			},
			
			
			// 点击列表右边,选择弹框
			async rightSelected(val) {
				if(!this.editType || !this.isChange) return
				this.rightItem = val
				// 分页
				let params = {
					pageIndex:1,
					pageSize:10
				}
				this.rightList = []
				
				if(val === 'serviceActivities'){//服务活动
					let res = await getActivitiesList(params)
					if(res.result === '1'){
						let oldList = res.rows.map(o => { return o.actionName })
						this.rightData(oldList,res.rows,'3')
					}
					
				} else if(val === 'packageBoutique'){//套餐精品（功能暂不写）
					this.$refs.uToast.show({
						title: '暂无数据',
						type: 'primary',
					})			
					// let res = await getSetMealList(this.params)
					// if(res.result === '1'){
					// 	let oldList = res.rows.map(o => { return o.actionName })
					// 	this.rightData(oldList)
					// }
					
				}else if(val === 'maintenanceProgram'){//保养项目
					let res = await getMaintenanceItem(params)
					if(res.result === '1'){
						let oldList = res.rows.map(o => { return o.repairModeName })
						this.rightData(oldList,res.rows,'1')
					}else {}
					
				}else if(val === "authorizedDlr"){//委外门店
					let res = await findOutDlrList()
					if(res.result === '1'){
						if(res.rows.length === 0){
							this.$refs.uToast.show({
								title: '暂无数据',
								type: 'primary',
							})	
							return
						}
						let oldList = res.rows.map(o => { return o.dlrName })
						this.rightData(oldList,res.rows,'0')
					}else {}
				}
			},
			// 请求之后显示数据
			rightData(oldList,rows,num){
				this.showSelected = true
				// let newList = [...new Set(oldList)]
				let newList = [...oldList]
				for(let i=0;i<newList.length;i++){
					this.rightList.push({})
					this.rightList[i].value = `${i}`
					this.rightList[i].label = newList[i]
					if(rows && rows.length>0 && num === '0'){//委外门店
						this.rightList[i].authorizedDlr = rows.find(o=>o.dlrName === newList[i]).authorizedDlr
					}
					if(rows && rows.length>0 && num === '1'){//保养项目
						this.rightList[i].repairModeId = rows.find(o=>o.repairModeName === newList[i]).repairModeId
					}
					if(rows && rows.length>0 && num === '3'){//服务活动
						this.rightList[i].actionId = rows.find(o=>o.actionName === newList[i]).actionId
						this.rightList[i].actionType = rows.find(o=>o.actionName === newList[i]).actionType
					}
				}
			},
			
			// 点击列表右边,选中选项最终值
			confirmSelected(val) {
				const that = this
				this.form[this.rightItem] = val[0].label
				//服务活动
				if(this.rightItem === 'serviceActivities' && this.rightList.length>0){
					let list={
						actionId: that.rightList.find(o=>o.label === val[0].label).actionId,
						actionType: that.rightList.find(o=>o.label === val[0].label).actionType,
					}
					this.form.listMapActivity=[]
					this.form.listMapActivity.push(list)
				}
				
				//委外门店
				if(this.rightItem === 'authorizedDlr'){
					this.form.authorizedDlr = this.rightList.find(o=>o.label === val[0].label).authorizedDlr
				}
				
				//保养项目
				if(this.rightItem === 'maintenanceProgram'){
					this.form.repairModeId = this.rightList.find(o=>o.label === val[0].label).repairModeId
					//调用接口查询费用信息
					this.queryCost()
				}
				
				//工时备件其他，更改维修类别
				if(this.rightList.length>0 && this.rightList[0].labelName){
					let inde=this.rightList[0].index
					if(this.rightList[0].labelName === "维修项目"){
						this.wisList[inde].retRepairType = val[0].label
						
						for(let key in this.rightList.find(o=>o.label === val[0].label)){
							this.wisList[inde][key] = this.rightList.find(o=>o.label === val[0].label)[key]
						}

					}else if(this.rightList[0].labelName === "维修备件"){
						this.partsList[inde].retRepairType = val[0].label
						
						for(let key in this.rightList.find(o=>o.label === val[0].label)){
							this.partsList[inde][key] = this.rightList.find(o=>o.label === val[0].label)[key]
						}
						
					}else{
						this.othersList[inde].retRepairType = val[0].label
						
						for(let key in this.rightList.find(o=>o.label === val[0].label)){
							this.othersList[inde][key] = this.rightList.find(o=>o.label === val[0].label)[key]
						}
					}
				}
				
				// 是否委外  outSourcing
				if(this.rightList.length>0 && this.rightList[0].outSourcing){
					let inde=this.rightList[0].index
					if(this.rightItem === 'item'){
						// this.wisList[inde].isEntrustCode = this.rightList.find(o=>o.label === val[0].label).label
						this.wisList[inde].isEntrust = val[0].label
						this.wisList[inde].isEntrustCode = val[0].value
					} else if(this.rightItem === "part"){
						this.partsList[inde].isEntrust = val[0].label
						this.partsList[inde].isEntrustCode = val[0].value
					} else{
						this.othersList[inde].isEntrust = val[0].label
						this.othersList[inde].isEntrustCode = val[0].value
					}
				}
				
				this.computedMoney6()
				
				this.form.listMapWi = this.wisList
				this.form.listMapPart = this.partsList
				this.form.listMapOther = this.othersList
				
				this.$emit('formEcho',this.form)
			},




			// 工时选择回调 (待优化)---维修项目
			receiveHours(arr) {
				if(!arr || arr.length === 0 ){
					return
				}
				
				for(let i=0;i<arr.length;i++){
					arr[i].isCanEdit = arr[i].is_can_edit ? arr[i].is_can_edit :''
					arr[i].saleWorkQty = arr[i].saleWiQty
				}
				
				if (!this.wisList || !this.wisList.length) {
					this.wisList = arr
					this.computedMoney6()
					return
				}
				// 已存在数据
				const wisIdList = this.wisList.map(wis => {
					return wis.wiId
				})
				// 选择数据
				const addArrIdList = arr.map(wis => {
					return wis.wiId
				})
				let sameType = false
				addArrIdList.forEach(addParts => {
					let index = wisIdList.indexOf(addParts)
					if (index === -1) {
						let addItem = arr.filter(item => {
							return item.wiId === addParts
						})
						this.wisList.push(addItem[0])
					} else {
						sameType = true
					}
				})
				if (sameType) {
					uni.showToast({
						title: '已选择重复数据!',
						duration: 2000,
						icon: "none"
					})
				}
			
				this.computedMoney6()
			},
			
			// 备件选择回调
			receiveParts(arr) {
				if(!arr || arr.length === 0 ){
					return
				}
				
				for(let i=0;i<arr.length;i++){
					arr[i].isCanEdit=arr[i].is_can_edit ? arr[i].is_can_edit :''
				}
				if (!this.partsList || !this.partsList.length) {
					this.partsList = arr
					this.computedMoney6()
					return
				}
				// 已存在数据
				const partsIdList = this.partsList.map(parts => {
					return parts.partId
				})
				// 选择数据
				const addArrIdList = arr.map(parts => {
					return parts.partId
				})
				let sameType = false
				addArrIdList.forEach(addParts => {
					let index = partsIdList.indexOf(addParts)
					if (index === -1) {
						let addItem = arr.filter(item => {
							return item.partId === addParts
						})
						this.partsList.push(addItem[0])
					} else {
						sameType = true
					}
				})
				if (sameType) {
					uni.showToast({
						title: '已选择重复数据请直接修改数量!',
						duration: 2000,
						icon: "none"
					})
				}
				console.log("partsList:",this.partsList)
				this.computedMoney6()
			},
			
			//其他选择
			receiveOthers(arr) {
				if(!arr || arr.length === 0 ){
					return
				}
				
				for(let i=0;i<arr.length;i++){
					arr[i].isCanEdit = arr[i].is_can_edit ? arr[i].is_can_edit :''
					arr[i].otherAmountType = arr[i].repairOtherName
				}
				
				if (!this.othersList || !this.othersList.length) {
					this.othersList = arr
					this.computedMoney6()
					return
				}
				// 已存在数据
				const otherIdList = this.othersList.map(other => {
					return other.repairOtherId
				})
				// 选择数据
				const addArrIdList = arr.map(other => {
					return other.repairOtherId
				})
				let sameType = false
				addArrIdList.forEach(addParts => {
					let index = otherIdList.indexOf(addParts)
					if (index === -1) {
						let addItem = arr.filter(item => {
							return item.repairOtherId === addParts
						})
						this.othersList.push(addItem[0])
					} else {
						sameType = true
					}
				})
				if (sameType) {
					uni.showToast({
						title: '已选择重复数据!',
						duration: 2000,
						icon: "none"
					})
				}
				this.computedMoney6()
			},
			
			// 打开公共页面
			openItem(v) {
				this.$refs[v].open = true
			},
			// 显示隐藏
			changeShrink(v) {
				this[v] = !this[v]
			},
			// 删除
			async deleteItem({
				item,
				arr,
				idName
			}) {
				const isContinue = await this.$Toast.toast('提示', '是否删除？')
				if (!isContinue) return
				const newArr = arr.filter(arrItem => {
					return arrItem[idName] != item[idName]
				})
				
				if (idName === 'partId') {
					this.partsList = newArr
				} else if(idName === 'wiId'){
					this.wisList = newArr
				} else {
					this.othersList = newArr
				}
				this.computedMoney6()
			},
			
			// 备件更改数量
			partsNumIndex(num,index){
				this.partsList[index].partQty = num
				this.computedMoney6()
			},
			
			
			// 计算维修项目价格
			computedMoney6(){
				// 工时备件其他
				this.form.wCoSts = 0
				this.form.pCoSts = 0
				this.form.oCoSts = 0
				// 索赔内部保险客户 总额
				this.form.spTotal=0
				this.form.nbTotal=0
				this.form.bxTotal=0
				this.form.khTotal=0
				
				for(let i=0;i<this.wisList.length;i++){
					let itemMoney = Number((this.wisList[i].saleWiQty * Number(this.wisList[i].wiPrice)).toFixed(2))
					this.form.wCoSts += itemMoney
					
					let val = Number(this.form.wCoSts)
					if(!isNaN(parseFloat(val))) {
						val = Number(val.toFixed(2));
					}
					this.form.wCoSts=val;
					
					
					if(
						this.wisList[i].repairTypeName === '免保' ||
					    this.wisList[i].repairTypeName === 'PDI' || 
						this.wisList[i].repairTypeName === '索赔'
					) {
						let itemMoney = Number((this.wisList[i].saleWiQty * Number(this.wisList[i].wiPrice)).toFixed(2))
						this.form.spTotal += Number((this.wisList[i].saleWiQty * Number(this.wisList[i].wiPrice)).toFixed(2))
						
						let val = Number(this.form.spTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.spTotal=val;
					} else if (
						this.wisList[i].repairTypeName === '外返' || 
						this.wisList[i].repairTypeName === '内返'
					){
						this.form.nbTotal += Number((this.wisList[i].saleWiQty * Number(this.wisList[i].wiPrice)).toFixed(2))
						
						let val = Number(this.form.nbTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.nbTotal=val;
					}else if(
						this.wisList[i].repairTypeName === '事故') {
						this.form.bxTotal += Number((this.wisList[i].saleWiQty * Number(this.wisList[i].wiPrice)).toFixed(2))
						
						let val = Number(this.form.bxTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.bxTotal=val;
					}else if(
						this.wisList[i].repairTypeName === '保养' || 
						this.wisList[i].repairTypeName === '机修' || 
						this.wisList[i].repairTypeName === '其他' || 
						this.wisList[i].repairTypeName === '延保'
						) {
						this.form.khTotal += Number((this.wisList[i].saleWiQty * Number(this.wisList[i].wiPrice)).toFixed(2))
						
						let val = Number(this.form.khTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.khTotal=val;
					}
					
				}
				for(let i=0;i<this.partsList.length;i++){
					let itemMoney = Number((this.partsList[i].partQty * Number(this.partsList[i].partPrice)).toFixed(2))
					
					this.form.pCoSts += itemMoney
					
					let val = Number(this.form.pCoSts)
					if(!isNaN(parseFloat(val))) {
						val = Number(val.toFixed(2));
					}
					this.form.pCoSts=val;

					
					if(
						this.partsList[i].repairTypeName === '免保' ||
					    this.partsList[i].repairTypeName === 'PDI' || 
						this.partsList[i].repairTypeName === '索赔'
					) {
						let itemMoney = Number((this.partsList[i].partQty * Number(this.partsList[i].partPrice)).toFixed(2))
						this.form.spTotal += Number((this.partsList[i].partQty * Number(this.partsList[i].partPrice)).toFixed(2))
						
						let val = Number(this.form.spTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.spTotal=val;
					} else if (
						this.partsList[i].repairTypeName === '外返' || 
						this.partsList[i].repairTypeName === '内返'
					){
						this.form.nbTotal += Number((this.partsList[i].partQty * Number(this.partsList[i].partPrice)).toFixed(2))
						
						let val = Number(this.form.nbTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.nbTotal=val;
					}else if(
						this.partsList[i].repairTypeName === '事故') {
						this.form.bxTotal += Number((this.partsList[i].partQty * Number(this.partsList[i].partPrice)).toFixed(2))
						
						let val = Number(this.form.bxTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.bxTotal=val;
					}else if(
						this.partsList[i].repairTypeName === '保养' || 
						this.partsList[i].repairTypeName === '机修' || 
						this.partsList[i].repairTypeName === '其他' || 
						this.partsList[i].repairTypeName === '延保'
						) {
						this.form.khTotal += Number((this.partsList[i].partQty * Number(this.partsList[i].partPrice)).toFixed(2))
						
						let val = Number(this.form.khTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.khTotal=val;
					}
				}
				
				for(let i=0;i<this.othersList.length;i++){
					this.form.oCoSts += Number((this.othersList[i].otherPrice).toFixed(2))
					
					if(
						this.othersList[i].repairTypeName === '免保' || this.othersList[i].repairTypeName === 'PDI' || this.othersList[i].repairTypeName === '索赔'
					) {
						let itemMoney = Number((this.othersList[i].otherPrice).toFixed(2))
						this.form.spTotal += Number((this.othersList[i].otherPrice).toFixed(2))
						
						let val = Number(this.form.spTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.spTotal=val;
					} else if (
						this.othersList[i].repairTypeName === '外返' || 
						this.othersList[i].repairTypeName === '内返'
					){
						this.form.nbTotal += Number((this.othersList[i].otherPrice).toFixed(2))
						
						let val = Number(this.form.nbTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.nbTotal=val;
					}else if(
						this.othersList[i].repairTypeName === '事故') {
						this.form.bxTotal += Number((this.othersList[i].otherPrice).toFixed(2))
						
						let val = Number(this.form.bxTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.bxTotal=val;
					}else if(
						this.othersList[i].repairTypeName === '保养' || 
						this.othersList[i].repairTypeName === '机修' || 
						this.othersList[i].repairTypeName === '其他' || 
						this.othersList[i].repairTypeName === '延保'
						) {
						this.form.khTotal += Number((this.othersList[i].otherPrice).toFixed(2))
						
						let val = Number(this.form.khTotal)
						if(!isNaN(parseFloat(val))) {
							val = Number(val.toFixed(2));
						}
						this.form.khTotal=val;
					}
				}
				
				// 工时备件其他 总额
				this.form.totals = this.form.wCoSts + this.form.pCoSts + this.form.oCoSts
				
				let val = Number(this.form.totals)
				if(!isNaN(parseFloat(val))) {
					val = Number(val.toFixed(2));
				}
				this.form.totals=val;
				
								
				this.form.listMapWi = this.wisList
				this.form.listMapPart = this.partsList
				this.form.listMapOther = this.othersList
				this.$emit('formEcho',this.form)
			},
			
		
			// 保养项目带出的费用
			async queryCost(){
				let params = {
					pageIndex:1,
					pageSize:10,
					repairModeId:this.form.repairModeId
				}
				// 1 维修项目
				let res1 = await importWiSel(params)
				// 2 维修备件
				let res2 = await importPartSel(params)
				// 3 其他费用
				let res3 = await importOtherSel(params)
				
				if(res1.result === '1' && res1.rows.length>0){
					this.wisList = []
					this.receiveHours(res1.rows)
				}
				if(res2.result === '1' && res2.rows.length>0){
					this.partsList = []
					this.receiveParts(res2.rows)
				}
				if(res3.result === '1' && res3.rows.length>0){
					this.othersList = []
					this.receiveOthers(res3.rows)
				}
				this.$emit('formEcho',this.form)
			},
			
			// 改变维修类型、选择是否委外
			async changePartType(val,labelName,index){
				this.rightItem=labelName === '维修项目'?'item':(labelName === '维修备件'?'part':'other')
				this.rightList = []
				
				if(val === '1'){
					let params = {
						pageIndex:1,
						pageSize:10,
					}
					let res = await repairTypeAndKind(params)
					if(res.result === '1'){
						if(res.rows && res.rows.length){
							let resData = res.rows
							for(let i=0;i<resData.length;i++){
								this.rightList.push({})
								this.rightList[i].value = `${i}`
								this.rightList[i].label = resData[i].repairTypeName
								
								for(let key in resData[i]){
									this.rightList[i][key] = resData[i][key]
								}
								
								this.rightList[i].labelName = labelName//做出标记方便回显
								this.rightList[i].index = index//做出标记方便回显
							}
						}
						this.showSelected = true
					}
				} else if(val === '2'){//是否委外
					this.rightList = [{
						value:'0',
						label:'否',
						outSourcing:'委外',//做出标记方便回显
						index:index
					},{
						value:'1',
						label:'是',
						outSourcing:'委外',//做出标记方便回显
						index:index
					}]
					this.showSelected = true
				}
				
				
			},
			
			// input离焦
			async inputBlur(val,v){
				let params = {
					pageIndex:1,
					pageSize:10,
				}
				if(v && val === 'carLicense'){//车牌号获得vin
					params.carLicense = this.form['carLicense']
					let res = await getCarInfoByVin(params)
					if(res.result === '1'){
						if(res.rows){
							this.form.vin=res.rows//vin
							this.queryVin(this.form.vin)
						}
					}else {
						return
					}
				}
			},
			// 通过vin查询行驶里程，上次建议项目，车辆/车主信息
			async queryVin(vin){
				let params = {
					vin:vin
				}
				let params1 = {
					vin:vin,
					isOtherCar: "0"
				}
				let res = await lastTimeProposal(params)//上次建议项目
				let resLc = await mileage(params)//行驶里程
				let resCar = await carInforList(params1)//车辆车主信息
				
				if(res.result === '1' && res.rows.length>0){
					this.scRecommendItem = res.rows[0].scRecommendItem
					this.form.scRecommendItem = this.scRecommendItem
				}
				
				if(resLc.result === '1' && resLc.rows.length>0){
					this.mileage = resLc.rows[0].mileage
					this.form.mileage = this.mileage
				}
				//客户车辆信息
				if(resCar.result === '1' && resCar.rows.length>0){
					this.form.paramMap = {...resCar.rows}
				}
			},
			
		},
	}
</script>

<style lang="scss" scoped>
	.repair-content {
		margin-top: 16rpx;

		.padding-lr {
			margin: 0 24rpx;
			background-color: #fff;
			margin-bottom: 16rpx;
			border-radius: 10rpx;
			padding: 0 20rpx 0 20rpx;

			.phoneColor {
				color: #4f75be;
			}
		}

		// 备件选择部分
		.category {
			margin: 0 24rpx;
			padding-bottom: 16rpx;
			border-radius: 10rpx;
		}

		// 底部费用合计
		.information-bottom {
			display: flex;
			flex-direction: column;
			background-color: #fff;
			margin-top: 16rpx;
			padding: 0 16rpx 16rpx 16rpx;

			.bottom-text {
				display: flex;
				flex-direction: row;
				padding: 30rpx 20rpx;
				justify-content: space-between;
				align-items: center;
				border-bottom: 1rpx solid #f5f5f5;
				color: #9f9f9f;

				.textColor {
					display: flex;
					align-items: center;
					font-weight: bold;
					color: #ff7947;

					.textSize {
						color: #333333;
					}
					.totalNum {
						font-size: 26px;
					}
				}
			}
		}
	}
</style>
